function cambiar_login() {
    document.querySelector('.cont_forms').className = "cont_forms cont_forms_active_login";
    document.querySelector('.cont_form_login').style.display = "block";
    document.querySelector('.cont_form_sign_up').style.opacity = "0";

    setTimeout(function () {
        document.querySelector('.cont_form_login').style.opacity = "1";
    }, 400);

    setTimeout(function () {
        document.querySelector('.cont_form_sign_up').style.display = "none";
    }, 200);
}

function cambiar_sign_up(at) {
    document.querySelector('.cont_forms').className = "cont_forms cont_forms_active_sign_up";
    document.querySelector('.cont_form_sign_up').style.display = "block";
    document.querySelector('.cont_form_login').style.opacity = "0";

    setTimeout(function () {
        document.querySelector('.cont_form_sign_up').style.opacity = "1";
    }, 100);

    setTimeout(function () {
        document.querySelector('.cont_form_login').style.display = "none";
    }, 400);


}

function ocultar_login_sign_up() {

    document.querySelector('.cont_forms').className = "cont_forms";
    document.querySelector('.cont_form_sign_up').style.opacity = "0";
    document.querySelector('.cont_form_login').style.opacity = "0";

    setTimeout(function () {
        document.querySelector('.cont_form_sign_up').style.display = "none";
        document.querySelector('.cont_form_login').style.display = "none";
    }, 500);

}

jQuery(function ($) {
    $.supersized({

        // Functionality
        slide_interval: 4000,    // Length between transitions
        transition: 1,    // 0-None, 1-Fade, 2-Slide Top, 3-Slide Right, 4-Slide Bottom, 5-Slide Left, 6-Carousel Right, 7-Carousel Left
        transition_speed: 1000,    // Speed of transition
        performance: 1,    // 0-Normal, 1-Hybrid speed/quality, 2-Optimizes image quality, 3-Optimizes transition speed // (Only works for Firefox/IE, not Webkit)

        // Size & Position
        min_width: 0,    // Min width allowed (in pixels)
        min_height: 0,    // Min height allowed (in pixels)
        vertical_center: 1,    // Vertically center background
        horizontal_center: 1,    // Horizontally center background
        fit_always: 0,    // Image will never exceed browser width or height (Ignores min. dimensions)
        fit_portrait: 1,    // Portrait images will not exceed browser height
        fit_landscape: 0,    // Landscape images will not exceed browser width

        // Components
        slide_links: 'blank',    // Individual links for each slide (Options: false, 'num', 'name', 'blank')
        slides: [    // Slideshow Images
            {image: 'https://img.tinshow.com/imgs/gamersky_007origin_013.jpg'}
        ]

    });

});

$(function () {
    $("#signup").click(function () {
        if ($("#display_name").val() == "") {
            layer.tips('请输入昵称', '#display_name');
            return;
        }
        if ($("#rei_email").val() == "") {
            layer.tips('请输入邮箱', '#rei_email');
            return;
        }
        if ($("#rei_pwd").val() == "") {
            layer.tips('密码不能为空', '#rei_pwd');
            return;
        }
        if ($("#rei_pwd").val().length < 6) {
            layer.tips('密码长度不能小于6哦', '#rei_pwd');
            return;
        }
        var index;
        var referer = document.referrer;

        $.ajax({
            type: "post",
            dataType: "json",
            url: "/signup",
            data: {
                display_name: filterXSS($("#display_name").val()),
                rei_email: $("#rei_email").val(),
                rei_pwd: $.md5($("#rei_pwd").val())
            },
            async: true,
            traditional: true,
            beforeSend: function () {
                index = layer.load(0, {shade: false});
            },
            success: function (data) {
                if (data.success == 1) {
                    layer.close(index);
                    window.location.href = "/signup/success/"+ data.id+"/"+data.time+"";
                } else if (data.msg == "displayName_exists") {
                    layer.close(index);
                    layer.tips('昵称已存在', '#display_name');
                } else if (data.msg == "email_exists") {
                    layer.close(index);
                    layer.tips('邮箱已存在', '#rei_email');
                } else {
                    layer.close(index);
                    layer.msg('注册失败');
                }
            }
        })
    });

    $("#login_btn").click(function () {
        var referer = document.referrer;
        if ($("#login_email").val() == "") {
            layer.tips('邮箱不能为空', '#login_email');
            return;
        }
        if ($("#login_pwd").val() == "") {
            layer.tips('密码不能为空', '#login_pwd');
            return;
        }
        $.ajax({
            type: "post",
            dataType: "json",
            url: "/login",
            data: {
                login_email: $("#login_email").val(),
                login_pwd: $.md5($("#login_pwd").val()),
                referfer_url: $("#referer").val()
            },
            async: true,
            traditional: true,
            success: function (result) {
                if (result.success == "1") {
                    if (referer) {
                        window.location.href = document.referrer;
                    } else {
                        window.location.href = "/";
                    }
                } else {
                    layer.msg('登录失败');
                    return;
                }
            }
        })
    });
})